﻿namespace CSharpBasic;

/// https://www.cnblogs.com/ccmonsor/p/15736123.html
/// 1、ReferenceEquals()
///  比较引用是否相同
/// 2、Equals()
///  是个虚方法，看需要可以进行重写
/// 3、== !=
///  不重写：引用类型比较的是通过判断两个引用是否指向同一个对象，值类型比较内容是否相同
///  重写：两个同时重写，

public struct ValueData
{
    public int a;
    public int b;

    public int CompareTo(object? value)
    {
        return 1;
    }

    public bool Equals(ValueData obj)
    {
        return a == obj.a && b == obj.b;
    }

    public static bool operator ==(ValueData lhs, ValueData rhs) => lhs.Equals(rhs);

    public static bool operator !=(ValueData lhs, ValueData rhs) => !(lhs == rhs);
}

public class CompareOperations
{
    public static void Main()
    {
        new CompareOperations().CompareOperation();
    }
    public void CompareOperation()
    {
        int a = 1;
        int b = a;
        bool isSameRef = ReferenceEquals(a, b);
        bool isSame = a.Equals(b);
        bool isEqualSame = a == b;

        ValueData _data_1 = new ValueData() { a = 1, b = 1 };
        ValueData _data_2 = new ValueData() { a = 1, b = 1 };
        bool structIsSame = _data_1.Equals(_data_2);
        // bool bb = _data_1 == _data_2;
    }
}